home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / sharew / packer / zlib / zfilter.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-17  |  1.5 KB  |  73 lines

  1. #include "zdef.h"
  2.  
  3. /*------------------------------*/
  4. /*    zfilter            */
  5. /*------------------------------*/
  6. #ifndef __STDC__
  7. ZFILE *zfilter (f)
  8. FILE   *f;
  9. #else
  10. ZFILE *zfilter (FILE *f)
  11. #endif
  12. {
  13.     register ZFILE *z;
  14.  
  15.     z = (ZFILE *) malloc (sizeof (ZFILE));
  16.     z->flags          = 0;
  17.     z->maxbits        = Z_BITS;    /* user settable max # bits/code */
  18.     z->free_ent       = 0;        /* first unused entry */
  19.     z->block_compress = BLOCK_MASK;
  20.     z->clear_flg      = 0;
  21.     z->init           = 0;
  22.  
  23.     z->zeof           = (0 != 0);
  24.     z->c1             = EOF;
  25.     z->c2             = EOF;
  26.     z->bufput         = 0;
  27.     z->bufget         = 0;
  28.     z->bufend         = Z_MAXBUF - 1;
  29.  
  30.     z->maxbits        = Z_BITS;    /* user settable max # bits/code */
  31.  
  32.     /*
  33.      *   Open input file
  34.      */
  35.     z->file = f;
  36.     if (z->file == (FILE *) NULL)
  37.     {
  38.         free (z);
  39.         z = (ZFILE *) NULL;
  40.     }
  41.  
  42.     /*
  43.      *   Check the magic number
  44.      */
  45.     if (z != (ZFILE *) NULL)
  46.     {
  47.         z->c1 = fgetc (z->file);
  48.         z->c2 = fgetc (z->file);
  49.         if ((z->c1 != 0x1F) || (z->c2 != 0x9D))
  50.         {
  51.             z->flags |= NOT_COMPRESSED;
  52.         }
  53.     }
  54.     if ((z == (ZFILE *) NULL) || ((z->flags & NOT_COMPRESSED) != 0))
  55.         return ((ZFILE *) z);
  56.  
  57.     z->maxbits        = fgetc (z->file);    /* set -b from file */
  58.     z->block_compress = z->maxbits & BLOCK_MASK;
  59.     z->maxbits       &= BIT_MASK;
  60.  
  61.     if (z->maxbits > Z_BITS)
  62.     {
  63.         fprintf (stderr,
  64.             "stdin compressed with %d bits; decompress can only handle %d bits\n",
  65.             z->maxbits, Z_BITS);
  66.         exit (0);
  67.     }
  68.     return ((ZFILE *) z);
  69. }
  70.  
  71.  
  72.  
  73.